package com.chixing.day10_hashcode_exception.word;

import java.util.Arrays;

public class StringSame {
    public static void main(String[] args) {
        String s = "anagram";
        String t = "magarbm";

        System.out.println(getCountAppear(s));
        System.out.println(getCountAppear(t));

        String[] strings1 = s.split("");
        String[] strings2 = t.split("");
        System.out.println(Arrays.toString(strings1));
        System.out.println(strings1[0].hashCode());
        System.out.println(strings1[1].hashCode());
        System.out.println(strings2[0].hashCode());
        System.out.println(strings2[1].hashCode());

        System.out.println(t.hashCode());
        System.out.println(getResult(s,t));
    }
    public static boolean getResult(String str1,String str2){
        if (str1.length()!=str2.length())
            return false;
        if (str1==str2)
            return false;
        if (getCountHash(str1)!=getCountHash(str2))
            return false;
        if (getCountAppear(str1)!=getCountAppear(str2))
            return false;
        return true;
    }


    public static int getCountHash(String str) {
        String[] strings = str.split("");
        int count = 0;
        for (int i=0;i<strings.length;i++){
            count+=strings[i].hashCode();
        }
        return count;
    }
    public static int getCountAppear(String str){
        char[] chars = str.toCharArray();
        int count = 0;
        for (int i = 0;i<chars.length;i++){
            for (int j =i+1;j<chars.length;j++){
                if (chars[i]==chars[j])
                    count++;
            }
        }
        return count;
    }
}
